import codecs
import binascii
import itertools
import re
import hashlib

encodings = ["bin", "md5"]


def bin_encode(input, errors=None):
    return ''.join("{:08b}".format(ord(c)) for c in input), len(input)


def bin_decode(input, errors=None):
    #input_iter= iter(input)
    return ''.join(chr(int(''.join(x),2)) for x in filter(lambda x: len(x)==8,re.split('(.{8})',input)))\
            , len(input) & ~7

def md5_encode(input, errors=None):
    return hashlib.md5(input).hexdigest(),len(input)

def md5_decode(input, errors=None):
    return "You thought too much!!!!!!!!",len(input)

def wSearcher(name):
    if name in encodings:
        return codecs.CodecInfo(name=name,
                                encode=eval(name+"_encode"),
                                decode=eval(name+"_decode"))

codecs.register(wSearcher)
